<!--
 * @Descripttion: 
 * @version: 
 * @Author: ewgof
 * @Date: 2020-08-31 16:51:01
 * @LastEditors: ewgof
 * @LastEditTime: 2020-09-23 20:54:31
-->
<!-- 内容部分 -->
<div id="container">
    <div class="layui-container">
        <div class="layui-row">
            <div class="layui-col-lg4 layui-col-md-offset4">
                <!-- 登录表单 -->
                <div class="login layui-form">
                    <h5 style="padding-bottom:0.6em;color:#FFFFFF;">用户名: </h5>
                    <div class="layui-form-item">
                        <input id="username" type="text" name="username" lay-verify="required" placeholder="用户名"
                            autocomplete="on" class="layui-input">
                    </div>
                    <h5 style="padding-bottom:0.6em;color:#FFFFFF;">密码: </h5>
                    <div class="layui-form-item">
                        <input id="password" type="password" name="password" lay-verify="required" placeholder="密码"
                            autocomplete="off" class="layui-input">
                    </div>
                    <h5 style="padding-bottom:0.6em;color:#FFFFFF;"> </h5>
                    <div class="layui-form-item">
                        <button class="layui-btn" lay-submit lay-filter="login">登录</button>
                    </div>
                    <!-- <div class="layui-form-item">
                        <label for="" class="layui-form-label">

                        </label>
                    </div> -->
                    <div class="layui-form-mid layui-word-aux">
                        <!-- 忘记密码？<a href="javascript:;" onclick="switchMainPage('reset-password')"
                            style="color: white;">重置密码</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -->
                        尚未有账号？点击<a href="javascript:;" onclick="switchMainPage('register')" style="color: white;">注册</a>
                    </div>
                </div>
                <!-- 登录表单END -->
            </div>
        </div>
    </div>
</div>
<!-- 内容部分end -->

<script src="./static/js/jquery.base64.js"></script>

<script>
    if (!window.btoa) window.btoa = $.base64.btoa
    if (!window.atob) window.atob = $.base64.atob

    layui.use('form', function () {
        var layer = layui.layer,
            form = layui.form;

        form.on('submit(login)', function (data) {
            var data = data.field;
            // console.log(data);
            $.ajax({
                url: window.config.api_url + 'api/login',
                method: 'post',
                data: { username: $.base64.btoa(data.username), password: $.base64.btoa(data.password) },
                dataType: 'json',
                processData: true,
                cache: false,
                headers: { rtime: window.func.getTime() },
                success: function (res) {
                    if (res.code == 0) {
                        var icon = 1;
                        localStorage.setItem('token', res.data.token);
                        localStorage.setItem('token_expire', res.data.expire);
                        localStorage.setItem('username', res.data.username);
                        localStorage.setItem('avatar', res.data.avatar);
                        window.location.href = './index.html';
                        form.render();
                    } else {
                        var icon = 2;
                    }
                    layer.msg(res.msg, { time: 1000, icon: icon });
                },
                fail: function () {
                    window.func.error();
                }
            });

            return false;
        });
        return false;
    });
</script>